package org.example.curriculum_design_6_16.entity.dto;

import lombok.Data;
import org.example.curriculum_design_6_16.entity.pojo.SocialService;

import java.util.Date;

/**
 * 社会服务数据传输对象
 */
@Data
public class SocialServiceDTO {
    
    private Integer id;
    private String studentId;
    private String serviceType;
    private String position;
    private String activityName;
    private Date startDate;
    private Date endDate;
    private Double duration;
    private Double score;
    private String academicYear;
    private String proofUrl;
    private Integer status;
    private String reviewComment;
    private Date createdAt;
    private Date updatedAt;
    
    // 扩展字段
    private String serviceTypeName; // 服务类型名称
    private String statusText; // 状态文本
    private String grade; // 等级
    
    /**
     * 从SocialService实体转换为DTO
     */
    public static SocialServiceDTO fromEntity(SocialService entity) {
        if (entity == null) {
            return null;
        }
        
        SocialServiceDTO dto = new SocialServiceDTO();
        dto.setId(entity.getId());
        dto.setStudentId(entity.getStudentId());
        dto.setServiceType(entity.getServiceType());
        dto.setPosition(entity.getPosition());
        dto.setActivityName(entity.getActivityName());
        dto.setStartDate(entity.getStartDate());
        dto.setEndDate(entity.getEndDate());
        dto.setDuration(entity.getDuration());
        dto.setScore(entity.getScore());
        dto.setAcademicYear(entity.getAcademicYear());
        dto.setProofUrl(entity.getProofUrl());
        dto.setStatus(entity.getStatus());
        dto.setReviewComment(entity.getReviewComment());
        dto.setCreatedAt(entity.getCreatedAt());
        dto.setUpdatedAt(entity.getUpdatedAt());
        
        // 设置状态文本
        if (entity.getStatus() != null) {
            switch (entity.getStatus()) {
                case 0:
                    dto.setStatusText("待审核");
                    break;
                case 1:
                    dto.setStatusText("已通过");
                    break;
                case 2:
                    dto.setStatusText("已拒绝");
                    break;
                default:
                    dto.setStatusText("未知状态");
            }
        }
        
        return dto;
    }
    
    /**
     * 转换为SocialService实体
     */
    public SocialService toEntity() {
        SocialService entity = new SocialService();
        entity.setId(this.id);
        entity.setStudentId(this.studentId);
        entity.setServiceType(this.serviceType);
        entity.setPosition(this.position);
        entity.setActivityName(this.activityName);
        entity.setStartDate(this.startDate);
        entity.setEndDate(this.endDate);
        entity.setDuration(this.duration);
        entity.setScore(this.score);
        entity.setAcademicYear(this.academicYear);
        entity.setProofUrl(this.proofUrl);
        entity.setStatus(this.status);
        entity.setReviewComment(this.reviewComment);
        entity.setCreatedAt(this.createdAt);
        entity.setUpdatedAt(this.updatedAt);
        return entity;
    }
} 